package cg.project.controller;

import cg.project.pojo.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("session")
public class SessionController {

    @GetMapping("add")
    public Result add(String username, HttpServletRequest request){
        HttpSession session = request.getSession();
        session.setAttribute("username",username);
        return new Result("200","session存储数据");
    }

    @GetMapping("get")
    public Result add(HttpServletRequest request){
        HttpSession session = request.getSession();
        String username = (String) session.getAttribute("username");
        return new Result("200","session存储数据",username);
    }



}